/*
 * File:   TranscriberMetaInfoTest.cpp
 * Author: Guilherme Monteiro
 *
 */

#include "TranscriberMetaInfoTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(TranscriberMetaInfoTest);

TranscriberMetaInfoTest::TranscriberMetaInfoTest() {
}

TranscriberMetaInfoTest::~TranscriberMetaInfoTest() {
}

void TranscriberMetaInfoTest::setUp() {
    this->model = new Model1();
    this->path = "/books/caracterizacao/baixa_resolucao/image278.png";
    
    this->dotdot = "..";
    
    this->bar = "/";
    
    this->books = "books";
    this->bookName = "caracterizacao";
    this->pageName = "image278";
    this->baixaResolucao = "baixa_resolucao";
    this->altaResolucao = "alta_resolucao";
    this->logImages = "logImages";
    this->tabelasAlta = "tabelasAlta";
    this->tabelasBaixa = "tabelasBaixa";
    this->entrada = "entrada";
    this->saida = "saida";
    this->metadados = "metadados";
    
    this->transcriberMetaInfo = new TranscriberMetaInfo(path, model);
}

void TranscriberMetaInfoTest::tearDown() {
}

void TranscriberMetaInfoTest::testTranscriberMetaInfo1() {
    string p = "";
    try {
        MetaInfo* transcriberMetaInfo2 = new TranscriberMetaInfo(p, model);
    }
    catch(NullImageException &nie) {
        string msg = "ERROR ==> Image " + p + " can't be loaded. Change the image path or the directory of execution";
        if ( strcmp(nie.what(), msg.c_str()) != 0 ) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void TranscriberMetaInfoTest::testTranscriberMetaInfo2() {
    string p = "/books/image1000.png";
    try {
        MetaInfo* transcriberMetaInfo2 = new TranscriberMetaInfo(p, model);
    }
    catch(NullImageException &nie) {
        string msg = "ERROR ==> Image " + p + " can't be loaded. Change the image path or the directory of execution";
        if ( strcmp(nie.what(), msg.c_str()) != 0 ) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void TranscriberMetaInfoTest::testGetBookName() {
    string result = transcriberMetaInfo->getBookName();
    string expect = bar + bookName;
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testGetHighResolutionImageCutIncompletePath() {
    string result = transcriberMetaInfo->getHighResolutionImageCutIncompletePath();
    string expect = dotdot + bar + books + bar + bookName + bar + metadados + bar + 
            tabelasAlta + bar + pageName;
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testGetHighResolutionImagePath() {
    string result = transcriberMetaInfo->getHighResolutionImagePath();
    string expect = dotdot + bar + books + bar + bookName + bar +
            altaResolucao + bar + pageName + ".png";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testGetInputFilePath() {
    string result = transcriberMetaInfo->getInputFilePath();
    string expect = dotdot + bar + books + bar + bookName + bar + metadados + bar
            + entrada + bar + pageName + ".txt";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testGetLogImageIncompletePath() {
    string result = transcriberMetaInfo->getLogImageIncompletePath();
    string expect = dotdot + bar + logImages + bar + pageName + "_" + model->getModelName();
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testGetLowResolutionImageCutIncompletePath() {
    string result = transcriberMetaInfo->getLowResolutionImageCutIncompletePath();
    string expect = dotdot + bar + books + bar + bookName + bar + metadados + bar + 
            tabelasBaixa + bar + pageName;
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testGetLowResolutionImagePath() {
    string result = transcriberMetaInfo->getLowResolutionImagePath();
    string expect = dotdot + bar + books + bar + bookName + bar +
            baixaResolucao + bar + pageName + ".png";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testGetOutputFilePath() {
    string result = transcriberMetaInfo->getOutputFilePath();
    string expect = dotdot + bar + books + bar + bookName + bar + metadados + bar
            + saida + bar + pageName + "_" + model->getModelName() + ".txt";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testGetPageName() {
    string result = transcriberMetaInfo->getPageName();
    string expect = bar + pageName + ".png";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TranscriberMetaInfoTest::testSetHighResolutionImagePath1() {
    string newP = "";
    try {
        transcriberMetaInfo->setHighResolutionImagePath(newP);
    }
    catch(NullImageException &nie) {
        string result = "ERROR ==> Image " + newP + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(result.c_str(), nie.what()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void TranscriberMetaInfoTest::testSetHighResolutionImagePath2() {
    string newP = "/books";
    try {
        transcriberMetaInfo->setHighResolutionImagePath(newP);
    }
    catch(NullImageException &nie) {
        string result = "ERROR ==> Image " + newP + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(result.c_str(), nie.what()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void TranscriberMetaInfoTest::testSetLowResolutionImagePath1() {
    string newP = "";
    try {
        transcriberMetaInfo->setLowResolutionImagePath(newP);
    }
    catch(NullImageException &nie) {
        string result = "ERROR ==> Image " + newP + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(result.c_str(), nie.what()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void TranscriberMetaInfoTest::testSetLowResolutionImagePath2() {
    string newP = "/books";
    try {
        transcriberMetaInfo->setLowResolutionImagePath(newP);
    }
    catch(NullImageException &nie) {
        string result = "ERROR ==> Image " + newP + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(result.c_str(), nie.what()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}
